package biz.paperMager;

import java.util.Collection;

import models.ExaminationOfPaper;
import models.Subject;
import utils.TransactionTemplate;
import dao.ExamOfPaprDao;
import dao.ExamOfPaprDaoHbnImpl;
import dao.SubjectDao;
import dao.SubjectDaoHbnImpl;

public class PaperMagerBizImpl implements PaperMagerBiz {
	private ExamOfPaprDao eopDao = new ExamOfPaprDaoHbnImpl();
	private SubjectDao subDao=new SubjectDaoHbnImpl();
	@Override
	public void addPaper(ExaminationOfPaper paper) {
		try {
			TransactionTemplate.beginTransaction();
			eopDao.addPaper(paper);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public void deletePaper(Long paperId) {
		try {
			TransactionTemplate.beginTransaction();
			eopDao.delPaperById(paperId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public Collection<ExaminationOfPaper> getAllPapers() {
		Collection<ExaminationOfPaper> eops = null;
		try {
			TransactionTemplate.beginTransaction();
			eops = eopDao.selAllPapers();
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return eops;
	}

	@Override
	public ExaminationOfPaper getPaperById(Long paperId) {
		ExaminationOfPaper eop = null;
		try {
			TransactionTemplate.beginTransaction();
			eop = eopDao.selPaperById(paperId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return eop;
	}

	@Override
	public void modifyPaper(ExaminationOfPaper paper) {
		try {
			TransactionTemplate.beginTransaction();
			eopDao.updatePaper(paper);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public Collection<Subject> getAllSubjects() {
		Collection<Subject> subjects=null;
		try {
			TransactionTemplate.beginTransaction();
			subjects=subDao.selAllSubject();
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return subjects;
	}

	@Override
	public Subject getSubjectById(Long subId) {
		Subject subject=null;
		try {
			TransactionTemplate.beginTransaction();
			subject=subDao.selSubjectMoreById(subId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return subject;
	}

	@Override
	public void modifySubject(Subject subject) {
		try {
			TransactionTemplate.beginTransaction();
			subDao.updateSubject(subject);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		
	}

}
